package com.fare.fdc.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.dayatang.domain.InstanceFactory;
import com.fare.taluo.application.plane.city.CityQueryApplication;
import com.fare.taluo.application.system.auth.UserInfoLogApplication;
import com.fare.taluo.conf.ConfigContainer;
import com.fare.taluo.conf.system.DefaultPropertiesLoader;
import com.fare.taluo.db.hbase.HBasePropertiesLoader;
import com.fare.taluo.db.hbase.HbaseDriverManager;
/**
 * 应用程序启动加载数据
 * @author xiangsf 2013-05-23
 *
 */
public class AppStartupListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		ConfigContainer.getInstance().destroy();
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.setProperty("webapp.root" , arg0.getServletContext().getRealPath("/"));
		//加载配置文件
		//系统默认的config.properties配置文件
		ConfigContainer.getInstance().register(DefaultPropertiesLoader.class);
		//hbase数据库配置文件(可以改为像jdbc.properties文件一样由spring加载)
		ConfigContainer.getInstance().register(HBasePropertiesLoader.class);
		//抓取数据相关配置
		ConfigContainer.getInstance().register(com.fare.taluo.core.domain.crawl.CrawlPropertiesLoader.class);
		//生成城市、机场选择框
		InstanceFactory.getInstance(CityQueryApplication.class).createCitySelect();
		//每次重启mofang后，对用户登录信息进行一次清理
		InstanceFactory.getInstance(UserInfoLogApplication.class).systemUpdate();
		
//		HbaseDriverManager.getInstance();
	}

}
